#function(td, input, output)
// 构造工程
// global td;

td.beg("doc","DDocument");

	td.set("s_template","default");
	td.set("flags#ddoc",0x0);
	td.set("version#ddoc",0x134FDF7);

	// 顶层组
	td.beg("topgroup1","DSymbolGrp");
		td.set("unit","");
		td.set("meshinfo","");
		td.set("material","");
		td.set("n_dp_level",0x0);
		td.set("flg_style#decorator",0x0);
		td.set("exp_extra#decorator","");
		td.set("opt_extra_mode#decorator",0x0);
		td.set("sym_extra_function#decorator","");
		td.set("sym_extra_npDistrib#decorator","");
		td.set("flg_npDistrib_show#decorator",0x0);
		td.set("transforms",[]);
		td.set("children",["source"]);     //
		td.set("reference","source");
	td.end();

	td.beg("vartable","DVariable");
		td.set("variables",[]);
		td.set("type#DVariable",0x0);
		td.set("script#var#DVariable","");
	td.end();
	
	td.beg("topgroup1","DSymbolGrp");
		td.set("unit","");
		td.set("meshinfo","");
		td.set("material","");
		td.set("n_dp_level",0x0);
		td.set("flg_style#decorator",0x0);
		td.set("exp_extra#decorator","");
		td.set("opt_extra_mode#decorator",0x0);
		td.set("sym_extra_function#decorator","");
		td.set("sym_extra_npDistrib#decorator","");
		td.set("flg_npDistrib_show#decorator",0x0);
		td.set("transforms",[]);
		td.set("children",[]);
	td.end();
	
	// 求解器参数
	td.beg("config","DParameterTD");
		td.set("unit","#ddoc.unit.emwave //微波工程常用单位(mm, ns, GHz)");
		td.set("bgmat","#ddoc.material.vacuum");
		td.set("fbox.lo.x","-300");
		td.set("fbox.lo.y","-300");
		td.set("fbox.lo.z","-300");
		td.set("fbox.hi.x","300");
		td.set("fbox.hi.y","300");
		td.set("fbox.hi.z","300");
		td.set("fbox.policy",0x1);
		td.set("border.lo.x",0x0);
		td.set("border.lo.y",0x0);
		td.set("border.lo.z",0x0);
		td.set("border.hi.x",0x0);
		td.set("border.hi.y",0x0);
		td.set("border.hi.z",0x0);
		td.set("symmetry.x#DParameterTD",0x0);
		td.set("symmetry.y#DParameterTD",0x0);
		td.set("symmetry.z#DParameterTD",0x0);
		td.set("time.step_max","1000");
		td.set("time.time_max","20.0");
		td.set("time.dt_ratio","0.9");
		td.set("time.dt_reference","1.0");
		td.set("time.policy",0x0);
		td.set("time.time_max_policy",0x1);
		td.set("time.time_cycle","20.0");
		td.set("time.scale_factor","4.0");
		td.set("pml.size","12");
		td.set("pml.type",0x1);
		td.set("pml.sigma","8.0");
		td.set("pml.alpha","0.0");
		td.set("pml.kappa","1.0");
		td.set("bloch.k.x","0");
		td.set("bloch.k.y","0");
		td.set("bloch.k.z","0");
		td.set("addspace.type",0x0);
		td.set("addspace.val","0.25*lambda.val");
		td.set("addspace.box.lo.x","0.25*lambda.val");
		td.set("addspace.box.lo.y","0.25*lambda.val");
		td.set("addspace.box.lo.z","0.25*lambda.val");
		td.set("addspace.box.hi.x","0.25*lambda.val");
		td.set("addspace.box.hi.y","0.25*lambda.val");
		td.set("addspace.box.hi.z","0.25*lambda.val");
		td.set("freq.min","1.0");
		td.set("freq.max","2.0");
		td.set("freq.nsp","101");
		td.set("freq.num","11");
		td.set("output.folder","$(FULLPATH).data");
		td.set("output.name","$(FILENAME)");
		td.set("output.model_policy",0x0);
		td.set("output.storage_policy",0x0);
		td.set("solver.microengine.policy",0x0);
		td.set("solver.microengine.size","31");
		td.set("solver.auto_end_db","30");
		td.set("solver.step_min","1000");
		td.set("solver.flags",0x1);
		td.set("solver.fillmethod",0x0);
		td.set("viewer.type",0x0);
		td.set("viewer.flags",0x0);
		td.set("viewer.slice",0x2);
		td.set("viewer.field",0x2);
		td.set("viewer.position","0");
	td.end();

	// 网格设置
	td.beg("meshsetting","DMeshsetting");
		td.set("meshinfo.basic.flags",0x0);
		td.set("meshinfo.basic.delta.x","10.0");
		td.set("meshinfo.basic.delta.y","10.0");
		td.set("meshinfo.basic.delta.z","10.0");
		td.set("meshinfo.basic.extend.x","0.0");
		td.set("meshinfo.basic.extend.y","0.0");
		td.set("meshinfo.basic.extend.z","0.0");
		td.set("meshinfo.refine.flags",0x427);
		td.set("meshinfo.refine.edge_factor","1.0");
		td.set("meshinfo.refine.vol_factor","1.0");
		td.set("meshinfo.snapping.flags",0x30016);
		td.set("meshinfo.config.flags",0x0);
		td.set("meshinfo.config.edge_fraction","3.0");
		td.set("meshinfo.config.vol_smooth_ratio","1.1");
		td.set("meshinfo.config.edge_additional_fine_cells",0x3);
		td.set("meshinfo.config.min_vertical_face_area","0.0");
		td.set("meshinfo.config.vol_additional_fine_cells","3");
		td.set("meshinfo.config.num_near","15");
		td.set("meshinfo.config.num_far","15");
		td.set("meshinfo.config.max_delta_ratio","1.2");
		td.set("meshinfo.config.delta_max_near.x","lambda.ref/10.0");
		td.set("meshinfo.config.delta_max_near.y","lambda.ref/10.0");
		td.set("meshinfo.config.delta_max_near.z","lambda.ref/10.0");
		td.set("meshinfo.config.delta_max_far.x","lambda.ref/10.0");
		td.set("meshinfo.config.delta_max_far.y","lambda.ref/10.0");
		td.set("meshinfo.config.delta_max_far.z","lambda.ref/10.0");
		td.set("meshinfo.config.delta_min.x","lambda.val");
		td.set("meshinfo.config.delta_min.y","dy*0.95");
		td.set("meshinfo.config.delta_min.z","dz*0.95");
		td.set("meshinfo.conformal.level_e",0x3);
		td.set("meshinfo.conformal.level_h",0x3);
		td.set("meshinfo.conformal.line_policy",0x2);
		td.set("meshinfo.conformal.line_fc_policy",0x1);
		td.set("meshinfo.conformal.flags",0xD);
		td.set("meshinfo.conformal.sglrt_ratio_enable","0.2");
		td.set("meshinfo.conformal.SC_error","3.0");
		td.set("meshinfo.conformal.Area_thres_v1","0.0");
		td.set("meshinfo.conformal.Area_thres_v2","0.05");
		td.set("meshinfo.conformal.Line_thres_v1","0.0");
		td.set("meshinfo.conformal.Line_thres_v2","0.05");
		td.set("meshinfo.conformal.flags_discretization",0x3);
		td.set("meshinfo.conformal.delta_line_gap","1e-8");
		td.set("meshinfo.conformal.delta_line_pc","1e-8");
		td.set("meshinfo.conformal.delta_loop_pc","1e-8");
		td.set("meshinfo.conformal.flg_delta_type",0x1);
		td.set("meshinfo.mesh.type",0x1);
		td.set("meshinfo.mesh.grid.x","50");
		td.set("meshinfo.mesh.grid.y","50");
		td.set("meshinfo.mesh.grid.z","50");
		td.set("padjust.type",0x0);
		td.set("padjust.policy",0x0);
		td.set("padjust.eps_absolute","");
		td.set("padjust.eps_bylambda","0.0001");
	td.end();

	// 计算模式（暂时使用自定义模式）
	td.beg("EMP","DWorkmodeCustom");
		td.set("unit","");
	td.end();

	td.beg("vacuum","DMaterialSimple");
		td.set("unit","");
		td.set("clr_material.color#Material#Material","#FFFFFF50");
		td.set("flg_material.extra#Material#Material",0x0);
		td.set("sym_temperatue#Material#Material","");
		td.set("exp_eps#Simple#Material","1");
		td.set("exp_sge#Simple#Material","0");
		td.set("exp_xmu#Simple#Material","1");
		td.set("exp_sgm#Simple#Material","0");
	td.end();

	td.beg("pec","DMaterialSimple");
		td.set("unit","");
		td.set("clr_material.color#Material#Material","#707070FF");
		td.set("flg_material.extra#Material#Material",0x0);
		td.set("sym_temperatue#Material#Material","");
		td.set("exp_eps#Simple#Material","@PEC");
		td.set("exp_sge#Simple#Material","0");
		td.set("exp_xmu#Simple#Material","1");
		td.set("exp_sgm#Simple#Material","0");
	td.end();

	td.beg("pmc","DMaterialSimple");
		td.set("unit","");
		td.set("clr_material.color#Material#Material","#32C80050");
		td.set("flg_material.extra#Material#Material",0x0);
		td.set("sym_temperatue#Material#Material","");
		td.set("exp_eps#Simple#Material","1");
		td.set("exp_sge#Simple#Material","0");
		td.set("exp_xmu#Simple#Material","@PMC");
		td.set("exp_sgm#Simple#Material","0");
	td.end();

	td.beg("signal_default","DFunctionTimeGaussF");
		td.set("unit","");
		td.set("freq","1.0");
		td.set("phase","270.0");
		td.set("exp_freq_width#TimeFunc#Gaussian","freq.max - freq.min");
		td.set("exp_freq_center#TimeFunc#Gaussian","freq.val");
		td.set("exp_time_shift_factor#TimeFunc#Gaussian","3.5");
		td.set("exp_bandwidth_min_rel#TimeFunc#Gaussian","0.05");
		td.set("exp_bandwidth_max_rel#TimeFunc#Gaussian","3.0");
		td.set("opt_peakwidth_def_type#TimeFunc#Gaussian",0x0);
		td.set("exp_peakwidth_def#TimeFunc#Gaussian","1/exp(1)");
		td.set("flg_bandwidth_check#TimeFunc#Gaussian",0x0);
		td.set("opt_time_window#TimeFunc#Gaussian",0x1);
		td.set("exp_edge_time_factor#TimeFunc#Gaussian","0.25");
		td.set("flg_phase_calib#TimeFunc#Gaussian",0x0);
	td.end();

 	td.beg("default","DTemplateTD");
		td.set("variable#DTemplate","vartable");
		td.set("dispatcher#DTemplate","postprocess");
		td.set("FDTD.parameter#DTemplate","config");
		td.set("FDTD.topgroup#DTemplate","topgroup1");
		td.set("FDTD.workmode#DTemplate","EMP");
		td.set("FDTD.meshsetting#DTemplate","meshsetting");
	td.end();


	td.beg("postprocess","DDispatcherOnce");
		td.set("unit","");
		td.set("post_type",0x1);
		td.set("extra_script","");
		td.set("extra_script_file","app:/scripting/library/monitor_postp/monitor_preload.mx");
	td.end();
	/*
		if(!is_nil(output))
		{
			// 保存到指定的文件名
			td.save(output);
		}
	*/
	    
    //fs.exists(input.output.path)
	local target_folder=input.output.fpath;
	switch(fs.exists(target_folder))
    {
    case 0:
        // 不存在，创建文件夹
        fs.mkdir(target_folder);
        logger.log_message("Create folder: %s", target_folder);
    case 1:
        // 错误是个文件
        logger.log_error("Cannot create folder: %s", target_folder);
        break;
    case 2:
    }
	td.run(0);

td.end();



